package fy.form.listen.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;

import org.apache.commons.logging.LogFactory;

import com.seeyon.apps.collaboration.manager.ColManager;
import com.seeyon.v3x.services.V3XLocator;

import fy.config.FyConfig;
import fy.form.listen.bean.CommonFlowBean;
import fy.util.DBUtil;

public class MyCommonFlowDao {

	private static org.apache.commons.logging.Log log = LogFactory
			.getLog(MyCommonFlowDao.class);

	public static CommonFlowBean getTempleteCodeBySummaryId(long summaryId) {
		CommonFlowBean bean = null;
		Connection conn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		try {

			conn = DBUtil.connect(FyConfig.getOA_DB_CONFIG());

			pst = conn
					.prepareStatement("select s.start_member_id, t.templete_number from col_summary s left join ctp_template t on s.templete_id = t.id where s.id = ?");
			
			pst.setLong(1, summaryId);

			rs = pst.executeQuery();
			
			if (rs.next()) {
				bean = new CommonFlowBean();
				bean.setUserID(rs.getLong(1));
				String number = rs.getString(2);
				bean.setTempleteCode(number == null ? "" : rs.getString(2));
			}

		} catch (Exception e) {
			e.printStackTrace();
			log.error("通过summaryId查询模板编号和表单发起人异常", e);
		} finally {
			DBUtil.close(rs, pst, conn);
		}
		log.info("查到的bean是："+bean);
		return bean;
	}

	public static long getSenderBySummaryId(long summaryId) throws Exception {
		long memberID = 0L;
		Connection conn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		try {
			conn = DBUtil.connect(FyConfig.getOA_DB_CONFIG());

			pst = conn
					.prepareStatement("select s.start_member_id, t.templete_number from col_summary s left join ctp_template t on s.templete_id = t.id where s.id = ?");
			
			pst.setLong(1, summaryId);

			rs = pst.executeQuery();
			if (rs.next()) {
				memberID = (rs.getLong(1));
			}

		} finally {
			DBUtil.close(rs, pst, conn);
		}
		return memberID;
	}
}
